﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShareIt_MVC3.Models;


namespace ShareIt_MVC3.Controllers
{
    /// <summary>
    ///  Dieser Controller dient zur Kontrolle der einzelnen Views in den Angelegenheiten der verleihenden Benutzer und zur Weiterleitung auf diese.
    /// </summary>
    public class LendingsController : MainController
    {
        //
        // GET: /Lendings/
        /// <summary>
        /// Übersicht Über alle Ausleihvorgänge.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            List<Lending> lendings = lendColl.GetAllLendings();
            return View(lendings);
        }

        //
        // GET: /Lendings/Details/5
        /// <summary>
        /// Detail-Ansicht bei Übergabe der ID.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Lendings/Create
        /// <summary>
        /// Create-View aufrufen.
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Lendings/Create
        /// <summary>
        /// Erzeugt in der Theorie einen Ausleihvorgang. Ist hier aber wegen der logig des Programms nicht von belangen.
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Lendings/Edit/5
        /// <summary>
        /// Zeigt den Edit-View.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Lendings/Edit/5
        /// <summary>
        /// Editiert in der Theorie einen Ausleihvorgang. Ist hier aber wegen der logig des Programms nicht von belangen.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Lendings/Delete/5
        /// <summary>
        /// Anzeigen des Lösch-views.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Lendings/Delete/5

        /// <summary>
        /// löschen eines Leihvorganges.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
               
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
